<template>
  <div>
    <span>获取验证码({{time}}s)</span>
  </div>
</template>
<script setup lang="ts">
import {ref, watch} from 'vue'

const time = ref<number>(5)
const props = defineProps(['codeFlag'])
const $emit = defineEmits(['getCodeFlag'])
watch(() => props.codeFlag,
    () => {
        let timer = setInterval(() => {
          time.value--;
          if (time.value === 0) {
            clearInterval(timer)
            $emit('getCodeFlag', false)
          }
        }, 1000);
    },
    {
      immediate: true//开始监听一次
    }
)
</script>

<style scoped lang="scss">

</style>
